package com.moyu.oasys.chat.container;

import cn.dev33.satoken.stp.SaLoginModel;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.web.socket.WebSocketSession;

import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author 赵彦博
 * @Date 2024/12/4 11:12
 */
public class SessionContainer {

    private static final ConcurrentHashMap<String, WebSocketSession> SESSIONS = new ConcurrentHashMap<>();

    public static void add(WebSocketSession session) {
        String username = (String) session.getAttributes().get("username");
//        String loginId = (String) StpUtil.getLoginId();
        SESSIONS.put(username, session);
    }

    public static void remove(WebSocketSession session) {
        String username = (String) session.getAttributes().get("username");
//        String loginId = (String) StpUtil.getLoginId();
        SESSIONS.remove(username);
    }

    public static Collection<WebSocketSession> values() {
        return SESSIONS.values();
    }

}
